Repository navigation
Conversation
…e matcher Replaces direct dependency on path-to-regexp@^1.9.0 with a built-in iterative, memoized NFA matcher and destination compiler in src/utils/path-pattern.ts. - Preserves Firebase Hosting redirect syntax (:name, :1, :name?, :name*, :name+, bare *, external URLs with ports, and destination query strings) that path-to-regexp v8/v9 broke. - Guarantees linear O(ops * pathname.length) worst-case matching time, eliminating catastrophic backtracking ReDoS classes. - Removes path-to-regexp@^1.9.0 (and transitive isarray@0.0.1) from dependencies and package-lock.json. - Documents breaking edge cases (inline regexes inside redirects[].source and non-greedy left-to-right matching on ambiguous non-dot multi-param segments) in changelog.txt.
There was a problem hiding this comment.
Code Review
This pull request replaces the path-to-regexp dependency with a custom, built-in linear-time redirect path matcher and compiler (path-pattern.ts) to mitigate potential ReDoS vulnerabilities and improve performance. The redirects middleware has been updated to use these new utilities, and comprehensive unit tests have been added to verify the new implementation. No review comments were provided, so there is no additional feedback to address.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #605.
Why
Upgrading
path-to-regexpfrom1.9.0to9.0.0(as in #605) breaks documented Firebase Hosting redirect syntax (:1numbered regex captures,:post*splats,:value?optional segments, external URL destinations with captures such ashttps://blog.myapp.com/:post, and?querydestinations). Meanwhile,path-to-regexp@1.9.0is on an unmaintained 1.x branch and relies on backtracking JavaScriptRegExpmatching.Summary
src/utils/path-pattern.tswith a zero-dependency tokenizer, iterative memoized NFA matcher (createPathMatcher), and destination template compiler (createPathCompiler)::name,:1,:name?,:name*,:name+, bare*, optional/partial prefixes, external URLs including explicit:port, and query strings) withoutObject.prototypelookup.src/middleware/redirects.tsto usecreatePathMatcherandcreatePathCompiler, removing therawMatch.split("/")workaround anddecodeURIComponent(...)round-trip so patterns likesource: "/blog/:post*"→destination: "https://blog.myapp.com/:post"and percent-encoded / raw-%destination query strings work cleanly.path-to-regexp(^1.9.0) frompackage.jsonand dropspath-to-regexp@1.9.0+isarray@0.0.1frompackage-lock.json.changelog.txt(undocumented inline regexes insideredirects[].sourceare no longer supported—useredirects[].regexinstead; ambiguous non-.multi-parameter segments like/:a-:bmatch non-greedily left-to-right).test/unit/utils/path-pattern.spec.ts(100% coverage, including ReDoS regression tests) and expandstest/unit/middleware/redirects.spec.ts.Verification
npm test(eslint+nyc mochawithre2active): 383 passing, 0 lint errors/warnings (src/utils/path-pattern.tsat 100% statements/branches/functions/lines)npm run build&npm run preparenpm run license:checknpm install --package-lock-only --ignore-scripts --registry=https://registry.npmjs.org(idempotent; no lockfile diff)